/*
 * =====================================================================================
 *
 *       Filename:  numSeq_1019.cc
 *
 *    Description:  find the ith digit in the seq s1s2...sk
 *
 *        Version:  1.0
 *
 *        Created:  09/17/2012 06:41:38 PM
 * =====================================================================================
 */
#include	<stdio.h>

typedef unsigned long long ull;
static const int arrsize = 32000;
unsigned long long skCount[arrsize];
unsigned long long totalCount[arrsize];

int findLimit()
{
    skCount[0] = 0; totalCount[0] = 0;
    int i, c = 1, w = 1;
    for (i = 1; i < arrsize; ++i)
    {
        skCount[i] = c;
        totalCount[i] = totalCount[i-1] + skCount[i];
		if (i == 9 || i == 99 || i==999 || i== 9999)
			++w;
		c += w;
        if (totalCount[i] >= 2147483647)
            break;
    }
    return i;
}

//TODO: arr add 0
// left <= x < right
int binarySearchTotal(int l, int h, ull x)
{
    h = h + 1;
    while (l + 1 < h) {
        int mid = (l+h) / 2;
        if (x < totalCount[mid])
            h = mid;
        else 
            l = mid;
    }
    return l;
}

int binarySearchSk(int l, int h, ull x)
{
    h = h + 1;
    while (l + 1 < h) {
        int mid = (l+h) / 2;
        if (x < skCount[mid])
            h = mid;
        else 
            l = mid;
    }
    return l;
}

int digitArr[8];
int findDigitsNo(int n)
{
    int count = 0;
    if (n == 0)
        return 1;
    while (n) {
        digitArr[count++] = n % 10;
        n /= 10;
    }
    return count;
}

int main(int argc, char *argv[])
{
    int T;
    int highLimit = findLimit();
    char digitch;
    
    while (scanf("%d", &T) == 1)
    {
        while (T--) {
            ull pos;
            scanf("%llu", &pos);
            int idx = binarySearchTotal(1, highLimit, pos);
            if (pos == totalCount[idx])
                digitch = '0' + idx % 10;
            else {
                ull remain = pos  - totalCount[idx];
                int skidx = binarySearchSk(1, idx+1, remain);
                if (remain == skCount[skidx])
                    digitch = '0' + skidx % 10;
                else 
                {
                    ull rr = remain - skCount[skidx];
                    int digitcount = findDigitsNo(skidx+1);
                    digitch = '0' + digitArr[digitcount-rr];
                }
            }
            printf ( "%c\n", digitch);
        }
    }
}
